package org.cypress.rtpack.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.*;

@Configuration
public class ThreadConfig {
    /**
     * 周期性任务线程池 - 10个固定线程
     */
    @Bean(name = "periodicTaskExecutor", destroyMethod = "shutdown")
    public ExecutorService periodicTaskExecutor() {
        return new ThreadPoolExecutor(
                20,  // corePoolSize
                20, // maxPoolSize
                60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100) // 任务队列容量
        );
    }

    private ThreadFactory threadFactory(String nameFormat, boolean daemon) {
        return r -> {
            Thread t = new Thread(r, String.format(nameFormat, Thread.currentThread().getId()));
            t.setDaemon(daemon);
            return t;
        };
    }
}